#ifndef RADMALI
#define RADMALI

#include "debug.h"
#include <string.h>

extern long g_radmallocfail;
#ifdef __RAD32__
  #include "malloc.h"

 #define radmalrad malloc
 #define radfrrad free

#else
  #ifdef __RADWIN__
    #ifdef RADStatus
      #define radmalrad(num) GlobalAllocPtr(GMEM_MOVEABLE|GMEM_SHARE,num)
      #define radfrrad GlobalFreePtr
    #else
      #define radmalloc(num) GlobalAllocPtr(GMEM_MOVEABLE|GMEM_SHARE,num)
      #define radfree GlobalFreePtr
    #endif
  #else
    #include "malloc.h"
    #define radmalrad(num) _fmalloc((int)num)
    #define radfrrad _ffree
  #endif
#endif

#ifndef radmalloc

#include "stdlib.h"

RCFUNC void PTR4* RADLINK radmalloc(u32 numbytes)
{
  void PTR4* temp;
//#ifdef DEBUGGING_ON
//char errbuf[256];
//#endif

  if (numbytes==0)
    return(0);
  temp=(numbytes!=0xffffffff)?radmalrad(numbytes):0;

//#ifdef DEBUGGING_ON
//sprintf (errbuf, "Radmalloc %ld at %x\n", numbytes,temp);
//write_trace(errbuf);
//#endif

#ifdef RADStatus
  if (!temp)
    StatusMessage("Not enough memory.",1);
#else
  #ifndef __RADWIN__ 
    if (!temp) {
//      fatalerror("  Not enough memory to load smack file!\r\n");
//      DOSOut("  Not enough memory.\r\n");
//      exit(16);
       g_radmallocfail=1;
       return(temp);
    }
  #endif
#endif
  return(temp);
}

RCFUNC void RADLINK radfree(void PTR4* ptr)
{
//#ifdef DEBUGGING_ON
//char errbuf[256];
//#endif
//#ifdef DEBUGGING_ON
//sprintf (errbuf, "Radfree at %x\n", ptr);
//write_trace(errbuf);
//#endif
  radfrrad(ptr);
}

#endif

#endif
